<?php
require_once '../include/conn.php';
require_once 'header.php';
require_once 'pager.php';

if($clause == "editinfo"){
    if($content == ''){HintAndBack("请输入快捷回复内容",1);}
    
    if($content != ''){  
        $sql = "insert into h_kefu_reply (h_content,h_addTime) values ('$content','" . date('Y-m-d H:i:s') . "')";
        $db->query($sql);
    }
	
	okinfo('?','添加成功！');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>快捷回复</title>
    <link rel="stylesheet" href="index.css">
</head>
<body>
    <div class="form-list">
        <form action="?clause=editinfo" method="post">
            <div class="table-title">快捷回复</div>
            <div class="table-list">
                <label>内容：</label>
                <input type="text" name="content" maxlength="300">
            </div>
            <div class="btn">
                <button class="text-center">确定添加</button>
            </div>
        </form>
    </div>
    <div class="table-item">
        <table>
            <tr style="height: 0px;">
            </tr>
            <tr>      
              <td>回复内容</td>
              <td>相关操作</td>
            </tr>
            <?php
			$total_count = $db->counter('h_kefu_reply', 'id');
			$list_num = 30;
			$page = (int)$page;
			if($page_input){$page=$page_input;}
			$rowset = new Pager($total_count,$list_num,$page);
			$from_record = $rowset->_offset();
			$query = "select * from `h_kefu_reply` order by h_addTime desc,id desc limit $from_record, $list_num";
			$result = $db->query($query);
			while($list = $db->fetch_array($result))
			{
				$rs_list[]=$list;
			}

			$page_list = $rowset->link(GetUrl(2) . "?page=");
			
			if(count($rs_list) > 0)
			{ 
				foreach ($rs_list as $key=>$val)
				{
            ?>     
                <tr>
                <td><?php echo $val['h_content']; ?></td>
                <td><a style="cursor:pointer;" onClick="javascript:hintandturn('确定要删除吗？数据将不可恢复！','?clause=delinfo&id=<?php echo $val['id']; ?>',true);">删除</a></td>
                </tr>
            <?php
				}
			}	
		    ?>
        </table>
        <?php if(count($rs_list) > 0) echo "<div class=\"page\" style=\"margin-top:10px;\">{$page_list}</div>";?>
    </div>
    <?php  
    if($clause == 'delinfo'){delinfo();}

    function delinfo()
    {
	global $db,$id;

	$query = "delete from `h_kefu_reply` where id = $id";
	$db->query($query);
	
    echo("<script type='text/javascript'> location.href='?'; </script>");
    exit;
    }
    ?>
    <script>
        function hintandturn(str,url,torf)
        {
            if(confirm(str) && torf){
                window.location=url;
                return true;
            }else{
                return false;
            }
        }
    </script>
</body>
</html>